package com.zjuh.taofood.biz.dao.ibatis;

import java.util.List;

import wint.lang.utils.StringUtil;

import com.zjuh.taofood.biz.dao.TopicItemDAO;
import com.zjuh.taofood.biz.dao.query.TopicItemQuery;
import com.zjuh.taofood.biz.domain.TopicItemDO;

public class TopicItemDAOIbatis extends BaseIbatisDAO implements TopicItemDAO {

	public long create(TopicItemDO topicItem) {
		return (Long)this.getSqlMapClientTemplate().insert("TopicItemDAO.create", topicItem);
	}

	public void delete(long id) {
		this.getSqlMapClientTemplate().update("TopicItemDAO.delete", id);
	}

	public void update(TopicItemDO topicItem) {
		this.getSqlMapClientTemplate().update("TopicItemDAO.update", topicItem);
	}

	public TopicItemDO queryById(long id) {
		return (TopicItemDO)this.getSqlMapClientTemplate().queryForObject("TopicItemDAO.queryById", id);
	}

	public TopicItemDO queryByItemId(long itemId) {
		return (TopicItemDO)this.getSqlMapClientTemplate().queryForObject("TopicItemDAO.queryByItemId", itemId);
	}

	@SuppressWarnings("unchecked")
	public List<TopicItemDO> searchTopicItems(TopicItemQuery topicItemQuery) {
		if (!StringUtil.isEmpty(topicItemQuery.getQ())) {
			topicItemQuery.setQ("%" + topicItemQuery.getQ() + "%");
		}
		return (List<TopicItemDO>)this.getSqlMapClientTemplate().queryForList("TopicItemDAO.searchTopicItems", topicItemQuery);
	}
	
	
	@SuppressWarnings("unchecked")
	public List<TopicItemDO> queryTopTopicItems(TopicItemQuery topicItemQuery) {
		return (List<TopicItemDO>)this.getSqlMapClientTemplate().queryForList("TopicItemDAO.queryTopTopicItems", topicItemQuery);
	}
	
}
